package Vista;

import Control.Control;
import Handler.DragAndDrop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;

/**
 *
 * @author araya
 */
public class HorarioAlternoInsertar1 extends javax.swing.JPanel {

    private Control control;
    private DragAndDrop dragAndDrop;

    JPopupMenu popupMenu = new JPopupMenu();
    private static String INSERT_CMD = "Eliminar";

    public HorarioAlternoInsertar1(Control pControl) {
        control = pControl;
        initComponents();
        jTable2.getColumnModel().getColumn(1).setPreferredWidth(100);
        jTable2.getColumnModel().getColumn(2).setPreferredWidth(100);
        jTable2.getColumnModel().getColumn(3).setPreferredWidth(100);
        jTable2.getColumnModel().getColumn(0).setPreferredWidth(50);
        dragAndDrop = new DragAndDrop(getjList1(), getProfesores(), getjTable2(), pControl, 2);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jScrollPane4 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        profesores = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jComboBox1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nombre", "Materia" }));
        jPanel1.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 40, -1, 30));

        jTextField1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 40, 140, 30));

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"7:00-7:40", null, null, null, null, null},
                {"7:40-8:20", null, null, null, null, null},
                {"8:25-9:05", null, null, null, null, null},
                {"9:05-9:45", null, null, null, null, null},
                {"10:05-10:45", null, null, null, null, null},
                {"10:45-11:25", null, null, null, null, null},
                {"11:30-12:10", null, null, null, null, null},
                {"12:10-12:50", null, null, null, null, null},
                {"1:30-2:10", null, null, null, null, null},
                {"2:10-2:50", null, null, null, null, null},
                {"2:55-3:35", null, null, null, null, null},
                {"3:35-4:15", null, null, null, null, null},
                {"4:25-5:05", null, null, null, null, null},
                {"5:05-5:45", null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Horas", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes"
            }
        ));
        jTable2.setSelectionBackground(new java.awt.Color(51, 204, 0));
        jScrollPane3.setViewportView(jTable2);
        if (jTable2.getColumnModel().getColumnCount() > 0) {
            jTable2.getColumnModel().getColumn(0).setPreferredWidth(2);
        }

        jPanel1.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 40, 690, 290));

        profesores.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Nombre", "Materia"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        profesores.setSelectionBackground(new java.awt.Color(51, 204, 0));
        profesores.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                profesoresMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(profesores);

        jPanel1.add(jScrollPane5, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 90, 310, 280));

        jList1.setMinimumSize(new java.awt.Dimension(50, 100));
        jScrollPane2.setViewportView(jList1);

        jPanel1.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 410, 260, 100));

        jLabel7.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        jLabel7.setText("Restricción del profesor ");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 340, -1, -1));

        jTextArea.setColumns(20);
        jTextArea.setRows(5);
        jScrollPane1.setViewportView(jTextArea);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 370, 690, 130));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Aulas");
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 380, 50, -1));

        jScrollPane4.setViewportView(jPanel1);

        add(jScrollPane4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 1100, 550));
		  JMenuItem menuItem = new JMenuItem(INSERT_CMD);
    menuItem.addActionListener(new InsertRowsActionAdapter(this));

    popupMenu.add(menuItem);
           MouseListener popupListener = new PopupListener();
       jTable2.addMouseListener(popupListener);
       jTable2.getTableHeader().addMouseListener(popupListener);
    }// </editor-fold>//GEN-END:initComponents

    private void profesoresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_profesoresMouseClicked
        //control.ImprimirLeccionesProfesores();
    }//GEN-LAST:event_profesoresMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    public javax.swing.JList jList1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    public javax.swing.JTable jTable2;
    public javax.swing.JTextArea jTextArea;
    public javax.swing.JTextField jTextField1;
    public javax.swing.JTable profesores;
    // End of variables declaration//GEN-END:variables

    public javax.swing.JList getjList1() {
        return jList1;
    }

    public javax.swing.JTable getjTable2() {
        return jTable2;
    }

    public javax.swing.JTable getProfesores() {
        return profesores;
    }

    class PopupListener extends MouseAdapter {

        public void mousePressed(MouseEvent e) {
            showPopup(e);
        }

        public void mouseReleased(MouseEvent e) {
            showPopup(e);
        }

        private void showPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    }

    void eliminar(ActionEvent e) {
        //JOptionPane.showMessageDialog(null, "algo se jodio");
        //control.eliminarDeHorario(jTable2.getSelectedRow(), jTable2.getSelectedColumn(),this);
    }

    protected void processWindowEvent(WindowEvent e) {
        this.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
        }
    }

    class InsertRowsActionAdapter implements ActionListener {

        HorarioAlternoInsertar1 adaptee;

        InsertRowsActionAdapter(HorarioAlternoInsertar1 adaptee) {
            this.adaptee = adaptee;
        }

        public void actionPerformed(ActionEvent e) {
            adaptee.eliminar(e);
        }
    }

}
